<a href='https://github.com/angular/angular.js/edit/v1.4.x/src/ngMock/angular-mocks.js?message=docs(ngMock)%3A%20describe%20your%20change...#L1880' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>


<h1>
  <code>ngMock</code>
</h1>


  <h2>Installation</h2>

  <p>First include <code>angular-mocks.js</code> in your HTML:</p>

  <pre><code>&lt;script src=&quot;angular.js&quot;&gt;&#10;&lt;script src=&quot;angular-mocks.js&quot;&gt;</code></pre>

  <p>You can download this file from the following places:</p>
  <ul>
    <li>
      <a href="https://developers.google.com/speed/libraries/devguide#angularjs">Google CDN</a><br>
      e.g. <code>//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-mocks.js</code>
    </li>
    <li>
      <a href="http://bower.io">Bower</a><br>
      e.g. <pre><code>bower install angular-mocks@X.Y.Z</code></pre>
    </li>
    <li>
      <a href="http://code.angularjs.org/">code.angularjs.org</a><br>
      e.g. <pre><code>&quot;//code.angularjs.org/X.Y.Z/angular-mocks.js&quot;</code></pre>
    </li>
  </ul>
  <p>where X.Y.Z is the AngularJS version you are running.</p>
  <p>Then load the module in your application by adding it as a dependent module:</p>
  <pre><code>angular.module(&#39;app&#39;, [&#39;ngMock&#39;]);</code></pre>

  <p>With that you&apos;re ready to get started!</p>


<h1 id="ngmock">ngMock</h1>
<p>The <code>ngMock</code> module provides support to inject and mock Angular services into unit tests.
In addition, ngMock also extends various core ng services such that they can be
inspected and controlled in a synchronous manner within test code.</p>
<div doc-module-components="ngMock"></div>

<div class="component-breakdown">
  <h2>Module Components</h2>
  
  <div>
    <h3 class="component-heading" id="object">Object</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/object/angular.mock">angular.mock</a></td>
        <td><p>Namespace from &#39;angular-mocks.js&#39; which contains testing related code.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="provider">Provider</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/provider/$exceptionHandlerProvider">$exceptionHandlerProvider</a></td>
        <td><p>Configures the mock implementation of <a href="api/ng/service/$exceptionHandler"><code>$exceptionHandler</code></a> to rethrow or to log errors
passed to the <code>$exceptionHandler</code>.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="service">Service</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$exceptionHandler">$exceptionHandler</a></td>
        <td><p>Mock implementation of <a href="api/ng/service/$exceptionHandler"><code>$exceptionHandler</code></a> that rethrows or logs errors passed
to it. See <a href="api/ngMock/provider/$exceptionHandlerProvider">$exceptionHandlerProvider</a> for configuration
information.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$log">$log</a></td>
        <td><p>Mock implementation of <a href="api/ng/service/$log"><code>$log</code></a> that gathers all logged messages in arrays
(one array per logging level). These arrays are exposed as <code>logs</code> property of each of the
level-specific log function, e.g. for level <code>error</code> the array is exposed as <code>$log.error.logs</code>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$interval">$interval</a></td>
        <td><p>Mock implementation of the $interval service.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$httpBackend">$httpBackend</a></td>
        <td><p>Fake HTTP backend implementation suitable for unit testing applications that use the
<a href="api/ng/service/$http">$http service</a>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$timeout">$timeout</a></td>
        <td><p>This service is just a simple decorator for <a href="api/ng/service/$timeout">$timeout</a> service
that adds a &quot;flush&quot; and &quot;verifyNoPendingTasks&quot; methods.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/service/$controller">$controller</a></td>
        <td><p>A decorator for <a href="api/ng/service/$controller"><code>$controller</code></a> with additional <code>bindings</code> parameter, useful when testing
controllers of directives that use <a href="api/ng/service/$compile#-bindtocontroller-"><code>bindToController</code></a>.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="type">Type</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/type/angular.mock.TzDate">angular.mock.TzDate</a></td>
        <td><p><em>NOTE</em>: this is not an injectable instance, just a globally available mock class of <code>Date</code>.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/type/$rootScope.Scope">$rootScope.Scope</a></td>
        <td><p><a href="api/ng/type/$rootScope.Scope">Scope</a> type decorated with helper methods useful for testing. These
methods are automatically available on any <a href="api/ng/type/$rootScope.Scope">Scope</a> instance when
<code>ngMock</code> module is loaded.</p>
</td>
      </tr>
      
    </table>
  </div>
  
  <div>
    <h3 class="component-heading" id="function">Function</h3>
    <table class="definition-table">
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.dump">angular.mock.dump</a></td>
        <td><p><em>NOTE</em>: this is not an injectable instance, just a globally available function.</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.module">angular.mock.module</a></td>
        <td><p><em>NOTE</em>: This function is also published on window for easy access.<br>
<em>NOTE</em>: This function is declared ONLY WHEN running tests with jasmine or mocha</p>
</td>
      </tr>
      
      <tr>
        <td><a href="api/ngMock/function/angular.mock.inject">angular.mock.inject</a></td>
        <td><p><em>NOTE</em>: This function is also published on window for easy access.<br>
<em>NOTE</em>: This function is declared ONLY WHEN running tests with jasmine or mocha</p>
</td>
      </tr>
      
    </table>
  </div>
  
</div>




